/***********************************************************************
 * Module:  WordBuilder.java
 * Author:  wuxinyang
 * Purpose: Defines the Class WordBuilder
 ***********************************************************************/

package com.witframework.plugin.lucene.extractor;

import java.io.InputStream;
import java.io.StringWriter;

import org.apache.poi.hdf.extractor.WordDocument;

import com.witframework.plugin.lucene.DocumentHandlerException;


/** @pdOid 19452e17-74b1-41a3-9573-4adde6a3703d */
public class WordTextExtractor implements InputStreamTextExtractor{
	public String getContents(InputStream is) {
		String contents = null;
		try {
			WordDocument wordDoc = new WordDocument(is);
			StringWriter sw = new StringWriter();
			wordDoc.writeAllText(sw);
			sw.close();
			contents = sw.toString();
		} catch (Exception e) {
			throw new DocumentHandlerException("Cannot extract text from a Word document", e);
		}
		return contents;
	}
}